package com.example.demo.init;

import com.baidu.bas.db.dao.EruptDao;
import com.deepzero.mmma.channel.AccountType;
import com.deepzero.mmma.channel.sms.account.AliSmsAccount;
import com.deepzero.mmma.channel.sms.account.TencentSmsAccount;
import com.deepzero.mmma.channel.wx_account.WxMaAccount;
import com.example.demo.model.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.transaction.Transactional;

/**
 * 注册通道channel
 * @author liuzhenchuan@foxmail.com
 * @date 2020/12/17
 */
@Service
@Order
@Slf4j
public class ChannelRegister implements CommandLineRunner {

    @Resource
    private EruptDao eruptDao;

    @Transactional(rollbackOn = Exception.class)
    @Override
    public void run(String... args) throws Exception {

        Channel mediaPlatform = new Channel("微信公众号", AccountType.weixinMP, WxMaAccount.fieldDefines(),
                "微信");
        eruptDao.persistIfNotExist(Channel.class,mediaPlatform,"name",mediaPlatform.getName());

        Channel miniApp = new Channel("微信小程序", AccountType.weixinMA, WxMaAccount.fieldDefines(),
                "微信");
        eruptDao.persistIfNotExist(Channel.class,miniApp,"name",miniApp.getName());

        Channel aliyunSMS = new Channel("阿里云短信", AccountType.aliyunSMS, AliSmsAccount.fieldDefines(),
                "短信");
        eruptDao.persistIfNotExist(Channel.class,aliyunSMS,"name",aliyunSMS.getName());

        Channel txyunSMS = new Channel("腾讯云短信", AccountType.txyunSMS, TencentSmsAccount.fieldDefines(),
                "短信");
        eruptDao.persistIfNotExist(Channel.class,txyunSMS,"name",txyunSMS.getName());


    }
}

